import { transform } from '@svgr/core'
import { readFile, readdir } from 'fs-extra'
export async function buildSvg(id: string, filePath: string) {
    const svgCode = await readFile(filePath, 'utf-8')
    const jsCode = await transform(
        svgCode,
        {
            plugins: ['@svgr/plugin-svgo', '@svgr/plugin-jsx', '@svgr/plugin-prettier'],
            icon: true,
            titleProp: true,
            descProp: true,
            svgProps: {
                id
            },
            replaceAttrValues: {
                id,
            }
        },
        {
            componentName: id.split('-').map(it => {
                return it[0].toUpperCase() + it.slice(1)
            }).join('')
        },
    )
    return jsCode;
}
import { buildSync } from 'esbuild'
export function buildContents(contents: string){
    return buildSync({
        stdin: {
            contents,
            sourcefile: 'sker-icon.js',
            loader: 'jsx',
            resolveDir: __dirname
        },
        define: { },
        bundle: true,
        format: 'iife',
        minify: true,
        sourcemap: false,
        target: ['chrome58'],
        outfile: './public/icon.js',
    })
}